package org.hhchat.leetcode.banarySearch;

public class code278_easy {
    /* The isBadVersion API is defined in the parent class VersionControl.
      boolean isBadVersion(int version); */

    static class Solution {
        public int firstBadVersion(int n) {
            int l = 1;
            int h = n;
            while (l <= h) {
                if (l == h) {
                    if (isBadVersion(l)) {
                        return l;
                    } else {
                        return l + 1;
                    }
                }
                int mid = l + (h - 1) / 2;
                if (isBadVersion(mid)) {
                    h = mid - 1;
                } else {
                    l = mid + 1;
                }
            }
            return l;
        }

        public boolean isBadVersion(int n) {
            if (n > 0) {
                return true;
            }
            return false;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.firstBadVersion(1));
    }
}
